<!DOCTYPE html>
<html>
<head>
	<include file="Public:header" />
	<!-- jqgrid-->
	<link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
	<input id="id" class="hide" value="<{$id}>"/>
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox ">
				<div class="ibox-content">
					<p>
						<button type="button" id="add" class="btn btn-white btn-sm btn-outline"><i
								class="fa fa-plus-square-o"></i>&nbsp;新增
						</button>
						<button type="button" id="edit" class="btn btn-white btn-sm btn-outline"><i
								class="fa fa-edit"></i>&nbsp;修改
						</button>
						<button type="button" id="editSchoolAreaSeq" class="btn btn-white btn-sm btn-outline"><i
								class="fa fa-sort-numeric-asc"></i>&nbsp;修改排序
						</button>
						<button type="button" id="del" class="btn btn-white btn-sm btn-outline"><i
								class="fa fa-trash-o"></i>&nbsp;删除
						</button>
					</p>
					<div class="jqGrid_wrapper">
						<table id="table_list"></table>
						<div id="pager_list"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
	$(document).ready(function () {
		//初始化
		$.jgrid.defaults.styleUI = 'Bootstrap';
		$("#table_list").jqGrid({
			url : '__URL__/schoolAreaList?id=' + $("#id").val(),
			datatype: "json",
			height: 450,
			autowidth: true,
			shrinkToFit: true,
			rowNum: 15,
			rowList: [10, 15, 30, 50],
			colNames : [ 'ID','学校', '区域名称', '店铺数量', '状态','创建时间','操作' ],
			colModel : [ {name : 'id',index : 'id'},
				{name : 'school',index : 'school'},
				{name : 'area_name',index : 'area_name'},
				{name : 'shopCount',index : 'shopCount'},
				{name : 'status',index : 'status',sortable : false,formatter : function(cellvalue, options, rowObject){
					if(cellvalue == 1) {
						content = '开启'
					}else if(cellvalue == 0) {
						content = '关闭';
					}
					return content;
				}},
				{name : 'create_time',index : 'create_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}},
				{name : 'status',index : 'status',sortable : false,formatter : function(cellvalue, options, rowObject){
					if(cellvalue == 1) {
						content = '<button class="btn btn-white btn-xs btn-outline" onclick="updateSchoolAreaStatus('+ rowObject.id +','+ 0 +')"><i class="fa fa-lock"></i>  关闭</button>';
					}else if(cellvalue == 0) {
						content = '<button class="btn btn-white btn-xs btn-outline" onclick="updateSchoolAreaStatus('+ rowObject.id +','+ 1 +')"><i class="fa fa-unlock"></i>  开启</button>';
					}
					return content;
				}}
			],
			pager: "#pager_list",
			viewrecords: true,
			hidegrid: false,
			sortname: "id",
			sortorder: "desc",
		});
		// 设置按钮
		$("#table_list").jqGrid('navGrid', '#pager_list', {
			edit: false,
			add: false,
			del: false,
			search: false
		}, {
			height: 200,
			reloadAfterSubmit: true
		});
		// 添加适配响应
		$(window).bind('resize', function () {
			var width = $('.jqGrid_wrapper').width();
			$('#table_list').setGridWidth(width);
		});
		//增
		$("#add").click(function () {
			layerDialog("新增", '__URL__/addSchoolArea?id=<php>echo $id;</php>', "90%", "360px", true);
		})

	});


	//关闭&开启
	function updateSchoolAreaStatus(id,islock) {
		layer.confirm('确定执行？', function(index){
			var index = layer.load(2);
			$.ajax({
				url:"__URL__/updateSchoolAreaStatus",
				type:"post",
				data:{'id':id,'field':'status','status':islock},
				success:function(json){
					var data = eval("("+json+")");
					if(data.status == 1){
						layer.msg(data.info);
						$('#table_list').trigger("reloadGrid");
					}else{
						layer.msg(data.info);
					}
					layer.close(index);
				}
			})
		});
	}

	//修改排序
	$("#editSchoolAreaSeq").click(function () {
		layerDialog("修改排序", '__URL__/editSchoolAreaSeq', "90%", "90%", true);
	})

	//改
	$("#edit").click(function () {
		var id = $("#table_list").jqGrid('getGridParam', 'selrow');
		if (id != null) {
			layerDialog("修改", '__URL__/editSchoolArea?id=' + id, "90%", "50%", true);
		} else {
			layer.msg("您没有选取数据！");
		}
	})

	//删
	$("#del").click(function () {
		var id = $("#table_list").jqGrid('getGridParam', 'selrow');
		if (id != null) {
			layer.confirm('确定执行？', function (index) {
				$.ajax({
					url: "__URL__/logicDelSchoolAreas",
					type: "post",
					data: {'id': id},
					success: function (json) {
						var data = eval("(" + json + ")");
						if (data.status == 1) {
							layer.msg(data.info);
							$('#table_list').trigger("reloadGrid");
						} else {
							layer.msg(data.info);
						}
					}
				})
				layer.close(index);
			});
		} else {
			layer.msg("您没有选取数据！");
		}
	})

</script>
</html>